package com.stone.message.adapter.infra.publisher;

import com.stone.message.adapter.domain.event.SendMessageEvent;

/**
 * 消息发送发布器，发布发送消息
 *
 * @author Mr_wenpan@163.com 2021/07/22 21:24
 */
public class MessageSendPublisher<T> {

    /**
     * 消息发送器
     */
    private final MessagePublisher messagePublisher;

    public MessageSendPublisher(MessagePublisher messagePublisher) {
        this.messagePublisher = messagePublisher;
    }

    /**
     * 当有需要发送的send消息时，需要调用此方法抛出发送事件通知消费
     *
     * @param queue 消息队列
     * @param t     消息实体
     */
    protected void onSendMessage(String queue, T t) {
        SendMessageEvent<T> sendMessageEvent = new SendMessageEvent<>(this);
        sendMessageEvent.setContent(t);
        sendMessageEvent.setQueue(queue);
        messagePublisher.publish(sendMessageEvent);
    }
}
